<?php /* $Id: viewer.php,v 1.25 2005/03/31 01:50:57 ajdonnison Exp $ */
//view posts
$forum_id = isset($_GET['forum_id']) ? $_GET['forum_id'] : 0;
$message_id = isset($_GET['message_id']) ? $_GET['message_id'] : 0;
$post_message = isset($_GET['post_message']) ? $_GET['post_message'] : 0;
$f = dpGetParam( $_POST, 'f', 0 );

// check permissions
$canRead = !getDenyRead( $m, $forum_id );
$canEdit = !getDenyEdit( $m, $forum_id );

if (!$canRead || ($post_message & !$canEdit)) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}

$df = $AppUI->getPref('SHDATEFORMAT');
$tf = $AppUI->getPref('TIMEFORMAT');

$q  = new DBQuery;
$q->addTable('forums');
$q->addTable('projects', 'p');
$q->addTable('users', 'u');
$q->addQuery('forum_id, forum_project,	forum_description, forum_owner, forum_name,
	forum_create_date, forum_last_date, forum_message_count, forum_moderated,
	user_username, contact_first_name, contact_last_name,
	project_name, project_color_identifier');
$q->addJoin('contacts', 'con', 'contact_id = user_contact');
$q->addWhere("user_id = forum_owner");
$q->addWhere("forum_id = $forum_id");
$q->addWhere("forum_project = project_id");
$q->exec(ADODB_FETCH_ASSOC);
$forum = $q->fetchRow();
$forum_name = $forum['forum_name'];
echo db_error();
$q->clear();

$start_date = intval( $forum['forum_create_date'] ) ? new CDate( $forum['forum_create_date'] ) : null;

// setup the title block
$titleBlock = new CTitleBlock( 'Forum' );
$titleBlock->addCell(
	arraySelect( $filters, 'f', 'size="1" class="text" onchange="document.filterFrm.submit();"', $f , true), '',
	'<form action="?m=forums&a=viewer&forum_id='.$forum_id.'" method="post" name="filterFrm">', '</form>'
);
$titleBlock->addCell();
$titleBlock->addButton($AppUI->_('Forum list'), '?m=forums');
$titleBlock->show();
?>
<table width="100%" cellspacing="0" cellpadding="4" border="0" class="infopanel">
<tr>
	<th colspan="2">
		<img src="images/discuss_grp.gif">&nbsp;<?=@$forum['forum_name']?>&nbsp;
		<?=$start_date ? '(Since: '.$start_date->format( $df ).')' : ''?>
	</th>
</tr>
<tr>
	<td>
		<table width="100%" cellspacing="0" cellpadding="3" border="0" class="list">
		<tr>
			<td align="left" nowrap><b><?=$AppUI->_( 'Related Project' )?></b></td>
		</tr>
		<tr class="second">
			<td style="padding-left: 16px"><?=$forum['project_name']?></td>
		</tr>
		<tr>
			<td align="left"><b><?=$AppUI->_( 'Owner' )?></b></td>
		</tr>
		<tr class="second">
			<td style="padding-left: 16px">
			<a href="javascript:User(<?=$forum['forum_owner']?>).show()">
			<?php
			echo $forum['contact_first_name'] . ' ' . $forum['contact_last_name'];
			if (intval( $forum['forum_id'] ) <> 0) {
				echo " (".$AppUI->_( 'moderated' ).") ";
			}?>
			</a>
			</td>
		</tr>
		</table>
	</td>
	<td width="60%" height="100%">
		<table width="100%" cellspacing="0" cellpadding="3" border="0" class="list" height="100%">
		<tr>
			<td align="left" nowrap><b><?=$AppUI->_('Description')?></b></td>
		</tr>
		<tr height="100%" class="second">
			<td valign="top"><?=@str_replace("\n", '<br/>',$forum['forum_description'])?></td>
		</tr>
		</table>
	</td>
</tr>
</table>

<?php
if ($post_message) {
	include(DP_CURRENT_MODULE_PATH.'/post_message.php');
} else if($message_id == 0) {
	include(DP_CURRENT_MODULE_PATH.'/view_topics.php');
} else {
	include(DP_CURRENT_MODULE_PATH.'/view_messages.php');
}
?>
